#include "ClientSdk.h"
#include "Manager.h"
#include "MiniDump.h"

CManager *pMan = NULL;
bool g_bInit = false;
static MiniDumper minDump(true);

CLIENT_SDK_API int InitDll(OnMessageCallback callback, void *pUser)
{
	if (pMan)
	{ 
		delete pMan;
		pMan = NULL;
	}

	pMan = new CManager(0, "", callback, pUser);
	if (!pMan)
		return -1;

	g_bInit = true;

	return 0;
}

CLIENT_SDK_API int ReleaseDll(void)
{
	if (pMan)
	{ 
		delete pMan;
		pMan = NULL;
	}

	g_bInit = false;

	return 0;
}

CLIENT_SDK_API int SetVideoPlayWindows(unsigned long ulLocalVideoWnd, unsigned long ulRemoteVideoWnd)
{
	if (!g_bInit || !pMan)
		return -1;

	pMan->SetPlayWindows(ulLocalVideoWnd, ulRemoteVideoWnd);

	return 0;
}

CLIENT_SDK_API int ConnectServer(const char *pSvrIp, unsigned short usPort)
{
	if (!g_bInit || !pMan)
		return -1;

	if (pMan->StartApp(pSvrIp, usPort))
		return 0;

	return -1;
}

CLIENT_SDK_API unsigned int GetWBWindowHandle(void)
{
	if (!g_bInit || !pMan)
		return -1;

	return pMan->GetWindowHandle();
}

CLIENT_SDK_API void ClearWbData(void)
{
	if (!g_bInit || !pMan)
		return ;

	pMan->ClearLocalWbData();
}

CLIENT_SDK_API int InitVideoCapture()
{
	if (!g_bInit || !pMan)
		return -1;

	return pMan->InitVideoCapture();
}

CLIENT_SDK_API int UpdateVideoCaptureDevice()
{
	if (!g_bInit || !pMan)
		return -1;

	return pMan->UpdateVideoCapture();
}

CLIENT_SDK_API int GetVideoCaptureDevice(char *pOutData, int *pOutDataLen)
{
	if (!g_bInit || !pMan)
		return -1;

	return pMan->GetVideoCaptrueDevice(pOutData, pOutDataLen);
}

CLIENT_SDK_API int StartVideoCapture(int nIndex, int nWidth, int nHeigth, int nFrameRate)
{
	if (!g_bInit || !pMan)
		return -1;
	
	return pMan->StartCaptrue(nIndex, nWidth, nHeigth, nFrameRate);
}

CLIENT_SDK_API int StartVideoCaptureEx(const char *pUIDName, int nWidth, int nHeigth, int nFrameRate)
{
	if (!g_bInit || !pMan)
		return -1;

	return pMan->StartCaptrueEx(pUIDName, nWidth, nHeigth, nFrameRate);
}

CLIENT_SDK_API int StopVideoCapture(int nIndex)
{
	if (!g_bInit || !pMan)
		return -1;

	return pMan->StopCapture(nIndex);
}

CLIENT_SDK_API int ShowSetDialogBox(const char *pUIDName, const char *pTitle, void *pParentWindow, int nX, int nY)
{
	if (!g_bInit || !pMan)
		return -1;

	pMan->ShowSetDialogBox(pUIDName, pTitle, pParentWindow, nX, nY);

	return 0;
}

CLIENT_SDK_API int ShowSetDialogBoxEx(int nIndex, const char *pTitle, void *pParentWindow, int nX, int nY)
{
	if (!g_bInit || !pMan)
		return -1;

	pMan->ShowSetDialogBoxEx(nIndex, pTitle, pParentWindow, nX, nY);

	return 0;
}
